# coding:utf-8

# 修复兼容性问题
import collections
import collections.abc
collections.Hashable = collections.abc.Hashable

# pip install pdfkit
# https:wkhtmltopdf.org/downloads.html  #需要下载安装
import pdfkit
from pydocx import PyDocX
# 下载安装后需要配置一下路径，也可以在电脑环境变量中添加  但是我试了没生效
config = pdfkit.configuration(wkhtmltopdf='D:/freedong/requiresoft/wkhtmltopdf/bin/wkhtmltopdf.exe')
# 1. pdfkit.from_string
# html = """
# <html>
# <head>
# <meta charset="utf-8" />
# </head>
# <body>
#   <p>你好</p>
# </body>
# </html>
# """
# pdfkit.from_string(html,'test2.pdf',configuration=config)
# 2. pdfkit.from_url
# pdfkit.from_url('https://www.imooc.com','test1.pdf',configuration=config)
# 3. pdfkit.from_file
# 需要安装pydocx  pip install pydocx

# 修复兼容性问题  不这样些会报错误
# import collections
# import collections.abc
# collections.Hashable = collections.abc.Hashable

html = PyDocX.to_html('简历1.docx')  #获取html字符串
pdfkit.from_string(html,'test3.pdf',configuration=config)

# html = PyDocX.to_html('简历1.docx')  #获取html字符串
# f = open('html1.html','w',encoding='utf-8')
# f.write(html)
# f.close()
#
# pdfkit.from_file('html1.html','test4.pdf',configuration=config)
